<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="账单下载批次" prop="downloadBatch">
        <el-input
          v-model="queryParams.downloadBatch"
          placeholder="请输入账单下载批次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账单周期(年月日yyyymmdd)" prop="billDate">
        <el-input
          v-model="queryParams.billDate"
          placeholder="请输入账单周期(年月日yyyymmdd)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账单下载时间" prop="downloadDay">
        <el-date-picker clearable
          v-model="queryParams.downloadDay"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择账单下载时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="账单支付方式" prop="payWay">
        <el-input
          v-model="queryParams.payWay"
          placeholder="请输入账单支付方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构号" prop="orgId">
        <el-input
          v-model="queryParams.orgId"
          placeholder="请输入机构号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构请求流水号" prop="orgFlowNo">
        <el-input
          v-model="queryParams.orgFlowNo"
          placeholder="请输入机构请求流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户号" prop="merchNo">
        <el-input
          v-model="queryParams.merchNo"
          placeholder="请输入商户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="终端号" prop="terminalNo">
        <el-input
          v-model="queryParams.terminalNo"
          placeholder="请输入终端号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流水号" prop="flowNo">
        <el-input
          v-model="queryParams.flowNo"
          placeholder="请输入流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户订单号" prop="merchOrderNo">
        <el-input
          v-model="queryParams.merchOrderNo"
          placeholder="请输入商户订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Paymax订单号" prop="paymaxOrderNo">
        <el-input
          v-model="queryParams.paymaxOrderNo"
          placeholder="请输入Paymax订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Paymax退款单号" prop="paymaxRefundNo">
        <el-input
          v-model="queryParams.paymaxRefundNo"
          placeholder="请输入Paymax退款单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易金额" prop="transAmount">
        <el-input
          v-model="queryParams.transAmount"
          placeholder="请输入交易金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手续费" prop="fee">
        <el-input
          v-model="queryParams.fee"
          placeholder="请输入手续费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易日期
(支付宝微信：yyyyMMdd
，代付的时候格式示例：2018-04-24 15:27:58.0)" prop="transDate">
        <el-input
          v-model="queryParams.transDate"
          placeholder="请输入交易日期
(支付宝微信：yyyyMMdd
，代付的时候格式示例：2018-04-24 15:27:58.0)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易时间(支付宝微信yyyyMMddHHmmss)" prop="transTime">
        <el-input
          v-model="queryParams.transTime"
          placeholder="请输入交易时间(支付宝微信yyyyMMddHHmmss)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单时间" prop="kjOrderDatetime">
        <el-input
          v-model="queryParams.kjOrderDatetime"
          placeholder="请输入订单时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付时间" prop="kjPayDatetime">
        <el-input
          v-model="queryParams.kjPayDatetime"
          placeholder="请输入支付时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易总价" prop="transTotalAmount">
        <el-input
          v-model="queryParams.transTotalAmount"
          placeholder="请输入交易总价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付渠道订单号" prop="paymentChannelOrderNo">
        <el-input
          v-model="queryParams.paymentChannelOrderNo"
          placeholder="请输入支付渠道订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实际结算金额" prop="actualSettleAmount">
        <el-input
          v-model="queryParams.actualSettleAmount"
          placeholder="请输入实际结算金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段1" prop="reserve1">
        <el-input
          v-model="queryParams.reserve1"
          placeholder="请输入预留字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段2" prop="reserve2">
        <el-input
          v-model="queryParams.reserve2"
          placeholder="请输入预留字段2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段3" prop="reserve3">
        <el-input
          v-model="queryParams.reserve3"
          placeholder="请输入预留字段3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段4" prop="reserve4">
        <el-input
          v-model="queryParams.reserve4"
          placeholder="请输入预留字段4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段5" prop="reserve5">
        <el-input
          v-model="queryParams.reserve5"
          placeholder="请输入预留字段5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标识,0:未删除，1：删除" prop="delFlg">
        <el-input
          v-model="queryParams.delFlg"
          placeholder="请输入删除标识,0:未删除，1：删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建用户ID" prop="createUserid">
        <el-input
          v-model="queryParams.createUserid"
          placeholder="请输入创建用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新用户ID" prop="updateUserid">
        <el-input
          v-model="queryParams.updateUserid"
          placeholder="请输入更新用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['accounting:file:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['accounting:file:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['accounting:file:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['accounting:file:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fileList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键 自增" align="center" prop="id" />
      <el-table-column label="账单下载批次" align="center" prop="downloadBatch" />
      <el-table-column label="账单周期(年月日yyyymmdd)" align="center" prop="billDate" />
      <el-table-column label="账单下载时间" align="center" prop="downloadDay" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.downloadDay, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="账单支付方式" align="center" prop="payWay" />
      <el-table-column label="机构号" align="center" prop="orgId" />
      <el-table-column label="机构请求流水号" align="center" prop="orgFlowNo" />
      <el-table-column label="商户号" align="center" prop="merchNo" />
      <el-table-column label="终端号" align="center" prop="terminalNo" />
      <el-table-column label="交易类型" align="center" prop="transType" />
      <el-table-column label="流水号" align="center" prop="flowNo" />
      <el-table-column label="商户订单号" align="center" prop="merchOrderNo" />
      <el-table-column label="Paymax订单号" align="center" prop="paymaxOrderNo" />
      <el-table-column label="Paymax退款单号" align="center" prop="paymaxRefundNo" />
      <el-table-column label="交易金额" align="center" prop="transAmount" />
      <el-table-column label="交易状态" align="center" prop="transStatus" />
      <el-table-column label="手续费" align="center" prop="fee" />
      <el-table-column label="交易日期
(支付宝微信：yyyyMMdd
，代付的时候格式示例：2018-04-24 15:27:58.0)" align="center" prop="transDate" />
      <el-table-column label="交易时间(支付宝微信yyyyMMddHHmmss)" align="center" prop="transTime" />
      <el-table-column label="订单时间" align="center" prop="kjOrderDatetime" />
      <el-table-column label="支付时间" align="center" prop="kjPayDatetime" />
      <el-table-column label="支付方式" align="center" prop="payType" />
      <el-table-column label="交易总价" align="center" prop="transTotalAmount" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" />
      <el-table-column label="支付渠道订单号" align="center" prop="paymentChannelOrderNo" />
      <el-table-column label="实际结算金额" align="center" prop="actualSettleAmount" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="预留字段1" align="center" prop="reserve1" />
      <el-table-column label="预留字段2" align="center" prop="reserve2" />
      <el-table-column label="预留字段3" align="center" prop="reserve3" />
      <el-table-column label="预留字段4" align="center" prop="reserve4" />
      <el-table-column label="预留字段5" align="center" prop="reserve5" />
      <el-table-column label="删除标识,0:未删除，1：删除" align="center" prop="delFlg" />
      <el-table-column label="创建用户ID" align="center" prop="createUserid" />
      <el-table-column label="更新用户ID" align="center" prop="updateUserid" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['accounting:file:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['accounting:file:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改拉卡拉下载的对账单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="账单下载批次" prop="downloadBatch">
          <el-input v-model="form.downloadBatch" placeholder="请输入账单下载批次" />
        </el-form-item>
        <el-form-item label="账单周期(年月日yyyymmdd)" prop="billDate">
          <el-input v-model="form.billDate" placeholder="请输入账单周期(年月日yyyymmdd)" />
        </el-form-item>
        <el-form-item label="账单下载时间" prop="downloadDay">
          <el-date-picker clearable
            v-model="form.downloadDay"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择账单下载时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="账单支付方式" prop="payWay">
          <el-input v-model="form.payWay" placeholder="请输入账单支付方式" />
        </el-form-item>
        <el-form-item label="机构号" prop="orgId">
          <el-input v-model="form.orgId" placeholder="请输入机构号" />
        </el-form-item>
        <el-form-item label="机构请求流水号" prop="orgFlowNo">
          <el-input v-model="form.orgFlowNo" placeholder="请输入机构请求流水号" />
        </el-form-item>
        <el-form-item label="商户号" prop="merchNo">
          <el-input v-model="form.merchNo" placeholder="请输入商户号" />
        </el-form-item>
        <el-form-item label="终端号" prop="terminalNo">
          <el-input v-model="form.terminalNo" placeholder="请输入终端号" />
        </el-form-item>
        <el-form-item label="流水号" prop="flowNo">
          <el-input v-model="form.flowNo" placeholder="请输入流水号" />
        </el-form-item>
        <el-form-item label="商户订单号" prop="merchOrderNo">
          <el-input v-model="form.merchOrderNo" placeholder="请输入商户订单号" />
        </el-form-item>
        <el-form-item label="Paymax订单号" prop="paymaxOrderNo">
          <el-input v-model="form.paymaxOrderNo" placeholder="请输入Paymax订单号" />
        </el-form-item>
        <el-form-item label="Paymax退款单号" prop="paymaxRefundNo">
          <el-input v-model="form.paymaxRefundNo" placeholder="请输入Paymax退款单号" />
        </el-form-item>
        <el-form-item label="交易金额" prop="transAmount">
          <el-input v-model="form.transAmount" placeholder="请输入交易金额" />
        </el-form-item>
        <el-form-item label="手续费" prop="fee">
          <el-input v-model="form.fee" placeholder="请输入手续费" />
        </el-form-item>
        <el-form-item label="交易日期
(支付宝微信：yyyyMMdd
，代付的时候格式示例：2018-04-24 15:27:58.0)" prop="transDate">
          <el-input v-model="form.transDate" placeholder="请输入交易日期
(支付宝微信：yyyyMMdd
，代付的时候格式示例：2018-04-24 15:27:58.0)" />
        </el-form-item>
        <el-form-item label="交易时间(支付宝微信yyyyMMddHHmmss)" prop="transTime">
          <el-input v-model="form.transTime" placeholder="请输入交易时间(支付宝微信yyyyMMddHHmmss)" />
        </el-form-item>
        <el-form-item label="订单时间" prop="kjOrderDatetime">
          <el-input v-model="form.kjOrderDatetime" placeholder="请输入订单时间" />
        </el-form-item>
        <el-form-item label="支付时间" prop="kjPayDatetime">
          <el-input v-model="form.kjPayDatetime" placeholder="请输入支付时间" />
        </el-form-item>
        <el-form-item label="交易总价" prop="transTotalAmount">
          <el-input v-model="form.transTotalAmount" placeholder="请输入交易总价" />
        </el-form-item>
        <el-form-item label="支付渠道订单号" prop="paymentChannelOrderNo">
          <el-input v-model="form.paymentChannelOrderNo" placeholder="请输入支付渠道订单号" />
        </el-form-item>
        <el-form-item label="实际结算金额" prop="actualSettleAmount">
          <el-input v-model="form.actualSettleAmount" placeholder="请输入实际结算金额" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="reserve1">
          <el-input v-model="form.reserve1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reserve2">
          <el-input v-model="form.reserve2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reserve3">
          <el-input v-model="form.reserve3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="reserve4">
          <el-input v-model="form.reserve4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="预留字段5" prop="reserve5">
          <el-input v-model="form.reserve5" placeholder="请输入预留字段5" />
        </el-form-item>
        <el-form-item label="删除标识,0:未删除，1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识,0:未删除，1：删除" />
        </el-form-item>
        <el-form-item label="创建用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入创建用户ID" />
        </el-form-item>
        <el-form-item label="更新用户ID" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFile, getFile, delFile, addFile, updateFile } from "@/api/accounting/file";

export default {
  name: "File",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 拉卡拉下载的对账单表格数据
      fileList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        downloadBatch: null,
        billDate: null,
        downloadDay: null,
        payWay: null,
        orgId: null,
        orgFlowNo: null,
        merchNo: null,
        terminalNo: null,
        transType: null,
        flowNo: null,
        merchOrderNo: null,
        paymaxOrderNo: null,
        paymaxRefundNo: null,
        transAmount: null,
        transStatus: null,
        fee: null,
        transDate: null,
        transTime: null,
        kjOrderDatetime: null,
        kjPayDatetime: null,
        payType: null,
        transTotalAmount: null,
        orderStatus: null,
        paymentChannelOrderNo: null,
        actualSettleAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        downloadBatch: [
          { required: true, message: "账单下载批次不能为空", trigger: "blur" }
        ],
        billDate: [
          { required: true, message: "账单周期(年月日yyyymmdd)不能为空", trigger: "blur" }
        ],
        downloadDay: [
          { required: true, message: "账单下载时间不能为空", trigger: "blur" }
        ],
        payWay: [
          { required: true, message: "账单支付方式不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询拉卡拉下载的对账单列表 */
    getList() {
      this.loading = true;
      listFile(this.queryParams).then(response => {
        this.fileList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        downloadBatch: null,
        billDate: null,
        downloadDay: null,
        payWay: null,
        orgId: null,
        orgFlowNo: null,
        merchNo: null,
        terminalNo: null,
        transType: null,
        flowNo: null,
        merchOrderNo: null,
        paymaxOrderNo: null,
        paymaxRefundNo: null,
        transAmount: null,
        transStatus: "0",
        fee: null,
        transDate: null,
        transTime: null,
        kjOrderDatetime: null,
        kjPayDatetime: null,
        payType: null,
        transTotalAmount: null,
        orderStatus: "0",
        paymentChannelOrderNo: null,
        actualSettleAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加拉卡拉下载的对账单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFile(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改拉卡拉下载的对账单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFile(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFile(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除拉卡拉下载的对账单编号为"' + ids + '"的数据项？').then(function() {
        return delFile(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('accounting/file/export', {
        ...this.queryParams
      }, `file_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
